<template>
  <div class="title">查看报告</div>
  <div v-if="reportFileList.length > 0" >
    <div v-for="(item, index) in reportFileList" :key="index" class="report-container">
      <div class="report-container__left">
        <img class="img" src="@/assets/image/report_icon.png" alt="">
        <div class="con">
          <div class="name">{{item.fileName}}</div>
          <div class="size">文件大小: {{item.fileSize}}</div>
          <div class="date">上传日期: {{item.createTime}}</div>
        </div>
      </div>
      <t-button theme="primary" @click="downloadFile(item.sjhgPath)">下载查看</t-button>
    </div>
  </div>

<div v-else class="table-container__empty">
        <img class="table-container__empty--img" src="@/assets/icons/svg/empty.svg" alt="">
        <div class="table-container__empty--text">还未上传报告，请耐心等待</div>
      </div>
</template>
<script setup>
import { getAssessReportOne } from '@/api/sjhg/assess'; 
import { downloadFile2 } from '@/api/sjhg/upload'; 
const props = defineProps({
  assessId: {
    type: Number,
    default: 0
  }
})
const reportFileList = ref([])
onMounted(async() => {
  await getAssessReportOneList();
})

const downloadFile = async (objectPath) => {
  try {
    // const response = await axios.get('/sjhg/minio/download', {
    //   params: { bucketName: bucket, objectPath },
    //   responseType: 'blob'
    // });

    var params = {}
    params.objectPath = objectPath
    const response = await downloadFile2(params);

    // 生成临时下载链接
    const url = window.URL.createObjectURL(new Blob([response]));
    const link = document.createElement('a');
    link.href = url;
    link.setAttribute('download', objectPath.split('/').pop() || 'file');
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
    window.URL.revokeObjectURL(url);
  } catch (error) {
    console.error('下载失败:', error);
  }
};


const getAssessReportOneList = async () => {
  var params = {}
  params.assessId = props.assessId
  getAssessReportOne(params)
      .then((res) => {
        console.log('出具报告返回 = ', res)
        if (res.code == 200) {
          reportFileList.value = res.data || []
          console.log('reportFileList.value = ', reportFileList.value)
        }
      }).finally(() => {
      });
}
</script>
<style lang="scss" scoped>
.report-container{
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border: 1px solid #DCDCDC;
  border-radius: 4px;
  margin-top: 16px;
  font-weight: 400;
  font-family: PingFang SC-Bold, PingFang SC;
  .img{
    width: 90px;
    height: 90px;
  }
  .name{
    font-size: 16px;
    color:#000000E5;
    margin-top: 4px;
  }
  .size{
    margin-top: 12px;
    line-height: 22px;
    color:#00000066;
    font-weight: 400;
    font-size: 14px;
  }
  .date{
    line-height: 22px;
    color:#00000066;
    font-weight: 400;
    font-size: 14px;
    margin-top: 2px;
  }
  .con{
    margin-left: 16px;

  }
  &__left{
    display: flex;
    
  }

}
.title{
  font-size: 18px;
  color: #252931;
  margin-top: 8px;
  font-weight: 500;
  font-family: PingFang SC-Bold, PingFang SC;
}
</style>